//
//  UserInfoView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/28.
//

#import "UserInfoView.h"
#import "CommonUtil.h"

@interface UserInfoView()
@property (strong, nonatomic) UIImageView * levelImageView;
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UIButton * followBtn;
@property (strong, nonatomic) UILabel * nameLabel;
@property (strong, nonatomic) UILabel * likedLabel;
@property (strong, nonatomic) UILabel * likednumLabel;
@end


@implementation UserInfoView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = AD(5);
        
        [self addSubview:self.iconImageView];
        [self addSubview:self.levelImageView];
        [self addSubview:self.nameLabel];
        [self addSubview:self.followBtn];
        [self addSubview:self.likedLabel];
        [self addSubview:self.likednumLabel];
        self.levelImageView.bottom = self.iconImageView.top;
        self.levelImageView.centerX = self.iconImageView.centerX;
    }
    return self;
}

-(void)setModel:(SortModel *)model{
    _model = model;
    self.levelImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon_sort_%zd",model.sortIndex+1]];

}


- (void)followBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected) {
        [sender setTitle:@"取消关注" forState:UIControlStateNormal];
        sender.backgroundColor = [UIColor lightGrayColor];
    }else{
        [sender setTitle:@"+关注" forState:UIControlStateNormal];
        sender.backgroundColor = RGB(255.0, 90.0, 117.0);
    }
}


-(UIImageView *)levelImageView{
    if (!_levelImageView) {
        _levelImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        CGFloat w = AD(20);
        _levelImageView.frame = CGRectMake(0,0, w, w);
    }
    return _levelImageView;
}


-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        CGFloat w = self.width-AD(40);
        _iconImageView.frame = CGRectMake(AD(20),-w/2, w, w);
        _iconImageView.layer.cornerRadius = w/2;
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}



-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _iconImageView.bottom + AD(3), self.width, AD(25))];
        _nameLabel.font = [UIFont systemFontOfSize:AD(15)];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.text = @"吴妍珠";
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}

-(UIButton *)followBtn{
    if (!_followBtn) {
        _followBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_followBtn setTitle:@"+关注" forState:UIControlStateNormal];
        _followBtn.backgroundColor = RGB(255.0, 90.0, 117.0);
        [_followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_followBtn addTarget:self action:@selector(followBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _followBtn.layer.cornerRadius = AD(5);
        _followBtn.clipsToBounds = YES;
        
        _followBtn.frame = CGRectMake(AD(15), _nameLabel.bottom + AD(2), self.width-AD(30), AD(30));
        _followBtn.titleLabel.font = [UIFont systemFontOfSize:AD(14)];
    }
    return _followBtn;
}

-(UILabel *)likedLabel{
    if (!_likedLabel) {
        _likedLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _followBtn.bottom + AD(3), self.width, AD(20))];
        _likedLabel.font = [UIFont systemFontOfSize:AD(14)];
        _likedLabel.textColor = [UIColor lightGrayColor];
        _likedLabel.text = @"粉丝";
        _likedLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _likedLabel;
}

-(UILabel *)likednumLabel{
    if (!_likednumLabel) {
        _likednumLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _likedLabel.bottom , self.width, AD(20))];
        _likednumLabel.font = [UIFont systemFontOfSize:AD(14)];
        _likednumLabel.textColor = RGB(255.0, 90.0, 117.0);
        _likednumLabel.text = @"26000";
        _likednumLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _likednumLabel;
}



@end
